package com.yunduansing.demo.web;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import com.yunduansing.demo.model.account.LoginUserModel;
import com.yunduansing.demo.model.common.CacheKeyPrefix;
import com.yunduansing.demo.model.common.PassportModel;
import com.yunduansing.demo.model.common.ResponseModel;
import com.yunduansing.demo.service.AccountService;
import com.yunduansing.demo.service.JwtService;
import com.yunduansing.demo.service.impl.AuthUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础基类
 */
@RestController
public abstract class BaseController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private RedisTemplate redisTemplate;
    private final String CACHE_KEY_PREFIX=CacheKeyPrefix.LOGIN_USER;
    @Value("${login.user.expires}")
    private long LoginUserExpire;
    @Autowired
    private JwtService jwtService;

    /**
     * 获取登录用户账号信息
     */
    protected PassportModel getPassport(){
        return jwtService.getLoginUser();
    }

    protected ResponseModel convertToResponseModel(boolean success,String errMsg){
        if(success) return ResponseModel.ok();
        return ResponseModel.error(errMsg);
    }

    protected ResponseModel ok(Object data){
        return ResponseModel.ok(data);
    }
}
